﻿<UserControl xmlns:my="clr-namespace:WpfControlLibrary;assembly=WpfControlLibrary"  x:Class="YLServerInterface.UserControls.ImageCutter"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:s="clr-namespace:YLServerInterface.UserControls.DiagramDesigner"
             mc:Ignorable="d" 
             x:Name="myc"
             d:DesignHeight="295" d:DesignWidth="382" Loaded="UserControl_Loaded">

    <UserControl.Resources>
        <!-- MoveThumb Template -->
        <ControlTemplate x:Key="MoveThumbTemplate" TargetType="{x:Type s:MoveThumb}">
            <Rectangle Fill="Transparent"/>
        </ControlTemplate>

        <!-- ResizeDecorator Template -->
        <ControlTemplate x:Key="ResizeDecoratorTemplate" TargetType="{x:Type Control}">
            <Grid >
                <s:ResizeThumb Height="3" Cursor="SizeNS" Margin="0 -4 0 0"
                       VerticalAlignment="Top" HorizontalAlignment="Stretch"/>
                <s:ResizeThumb Width="3" Cursor="SizeWE" Margin="-4 0 0 0"
                       VerticalAlignment="Stretch" HorizontalAlignment="Left"/>
                <s:ResizeThumb Width="3" Cursor="SizeWE" Margin="0 0 -4 0"
                       VerticalAlignment="Stretch" HorizontalAlignment="Right"/>
                <s:ResizeThumb Height="3" Cursor="SizeNS" Margin="0 0 0 -4"
                       VerticalAlignment="Bottom" HorizontalAlignment="Stretch"/>
                <s:ResizeThumb Width="7" Height="7" Cursor="SizeNWSE" Margin="-6 -6 0 0"
                       VerticalAlignment="Top" HorizontalAlignment="Left"/>
                <s:ResizeThumb Width="7" Height="7" Cursor="SizeNESW" Margin="0 -6 -6 0"
                       VerticalAlignment="Top" HorizontalAlignment="Right"/>
                <s:ResizeThumb Width="7" Height="7" Cursor="SizeNESW" Margin="-6 0 0 -6"
                       VerticalAlignment="Bottom" HorizontalAlignment="Left"/>
                <s:ResizeThumb Width="7" Height="7" Cursor="SizeNWSE" Margin="0 0 -6 -6"
                       VerticalAlignment="Bottom" HorizontalAlignment="Right"/>
            </Grid>
        </ControlTemplate>


        <!-- Designer Item Template-->
        <ControlTemplate x:Key="DesignerItemTemplate" TargetType="ContentControl">
            <Grid DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}">
                <s:MoveThumb Template="{StaticResource MoveThumbTemplate}" Cursor="SizeAll"/>
                <Control Template="{StaticResource ResizeDecoratorTemplate}"/>
                <ContentPresenter Content="{TemplateBinding ContentControl.Content}"/>
            </Grid>
        </ControlTemplate>
    </UserControl.Resources>
    <Grid AllowDrop="True">
        <Grid.RowDefinitions>
            <RowDefinition Height="30"></RowDefinition>
            <RowDefinition></RowDefinition>
            <RowDefinition Height="30"></RowDefinition>
        </Grid.RowDefinitions>
        <TextBlock Name="tbSaveName" HorizontalAlignment="Center" VerticalAlignment="Center">不会裁剪</TextBlock>
        <Viewbox Grid.Row="1" Name="vbContainer">
            <Grid>

                <Image  Name="img" Stretch="UniformToFill"  SizeChanged="img_SizeChanged"   />
                <Canvas Name="canvas" >
                    <ContentControl  
                        Name="rect"
                        Template="{StaticResource DesignerItemTemplate}" 
                        Canvas.Left="1"
                        Canvas.Top="1"
                         MouseWheel="rect_MouseWheel"  >
                        <Rectangle 
                            Opacity="1" 
                           HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                            IsHitTestVisible="False" />
                    </ContentControl>
                    <Label Content="图片分辨率不符合裁剪要求。" Height="Auto" HorizontalAlignment="Center" Margin="0" Name="labError" VerticalAlignment="Center" FontSize="20" Visibility="Hidden" />

                </Canvas>
            </Grid>
        </Viewbox>
        <Grid Grid.Row="2" Name="gMove" Visibility="Visible">
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
                <Button Name="mLeft"  Click="mLeft_Click">左移</Button>
                <Button Name="mRight"  Click="mRight_Click">右移</Button>
            </StackPanel>
        </Grid>
    </Grid>
</UserControl>

    